package com.example.lab2;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class SearchAdapter extends RecyclerView.Adapter<TextViewHolder> {
    private ArrayList<String> initialDataSet=new ArrayList<>();
    private ArrayList<String> currentSet=new ArrayList<>();
    public SearchAdapter(){
        for(int i=1;i<100;i++){
            initialDataSet.add("这是第"+i+"条");
        }
        currentSet.addAll(initialDataSet);
    }
    @NonNull
    @Override
    public TextViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TextViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recycleview_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull TextViewHolder holder, int position) {
        holder.bind(currentSet.get(position));
    }

    @Override
    public int getItemCount() {
        return currentSet.size();
    }

    public void search(String key){
        currentSet.clear();
        for(String s:initialDataSet){
            if(s.contains(key)){
                currentSet.add(s);
            }
        }
        notifyDataSetChanged();
        Log.e("______-----------____", "--------search: "+key);
        Log.e("",initialDataSet.get(0));
    }
}
